package com.ev.asl.service.impl;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ev.asl.constant.AslConstant;
import com.ev.asl.dao.MoldingDailyDao;
import com.ev.asl.domain.MoldingDailyDO;
import com.ev.asl.domain.MoldingProductionInstructionDO;
import com.ev.asl.dto.MoldingDailyDto;
import com.ev.asl.service.KisBasicsService;
import com.ev.asl.service.KisBillOfPushService;
import com.ev.asl.service.MoldingDailyService;
import com.ev.asl.service.MoldingProductionInstructionService;
import com.ev.asl.vo.ApiResultVO2S;
import com.ev.asl.vo.voBillOfPull.KisReceiveStockVo;
import com.ev.custom.domain.DictionaryDO;
import com.ev.custom.domain.FacilityDO;
import com.ev.custom.domain.MaterielDO;
import com.ev.custom.service.DictionaryService;
import com.ev.custom.service.FacilityService;
import com.ev.custom.service.MaterielService;
import com.ev.custom.service.NoticeService;
import com.ev.framework.config.Constant;
import com.ev.framework.config.ConstantForGYL;
import com.ev.framework.exception.BDException;
import com.ev.framework.utils.*;
import com.ev.k3cloud.service.kingdeeMiddlewareService;
import com.ev.mes.dao.ProductionFeedingDetailDao;
import com.ev.mes.domain.*;
import com.ev.mes.vo.WorkTimeVO;
import com.ev.scm.domain.StockInDO;
import com.ev.scm.domain.StockInItemDO;
import com.ev.scm.domain.StockOutDO;
import com.ev.scm.domain.StockOutItemDO;
import com.ev.system.domain.UserDO;
import com.ev.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 姚家乐
 * @since 2021/6/2 13:49
 */
@Slf4j
@Service
public class MoldingDailyServiceImpl implements MoldingDailyService {

    //基本路
    @Value("${org.ftp.basePath}")
    private String basePath;
    //本地路径
    @Value("${org.ftp.localPath}")
    private String localPath;

    @Autowired
    private MoldingDailyDao                     dao;

    @Autowired
    private NoticeService noticeService;


    @Autowired
    private kingdeeMiddlewareService            kingdeeMiddlewareService;

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private FacilityService facilityService;

    @Autowired
    private MaterielService materielService;

    @Autowired
    private KisBasicsService kisBasicsService;

    @Autowired
    private KisBillOfPushService kisBillOfPushService;

    @Autowired
    private ProductionFeedingDetailDao productionFeedingDetailDao;

    @Autowired
    private UserService userService;


    @Autowired
    private MoldingProductionInstructionService moldingProductionInstructionService;

    @Override
    public Integer save(MoldingDailyDO entity) {
        return dao.save(entity);
    }

    @Override
    @Transactional
    public Integer save(MoldingDailyDto dto) {
        Map<String, String> map = new HashMap<>();
        map.put("startTime1", dto.getStartTime1());
        map.put("startTime2", dto.getStartTime2());
        map.put("startTime3", dto.getStartTime3());
        map.put("startTime4", dto.getStartTime4());
        map.put("startTime5", dto.getStartTime5());
        map.put("startTime6", dto.getStartTime6());
        map.put("startTime7", dto.getStartTime7());
        map.put("startTime8", dto.getStartTime8());
        map.put("startTime9", dto.getStartTime9());
        map.put("startTime10", dto.getStartTime10());
        map.put("startTime11", dto.getStartTime11());
        map.put("startTime12", dto.getStartTime12());
        map.put("startTime13", dto.getStartTime13());
        map.put("startTime14", dto.getStartTime14());
        map.put("endTime1", dto.getEndTime1());
        map.put("endTime2", dto.getEndTime2());
        map.put("endTime3", dto.getEndTime3());
        map.put("endTime4", dto.getEndTime4());
        map.put("endTime5", dto.getEndTime5());
        map.put("endTime6", dto.getEndTime6());
        map.put("endTime7", dto.getEndTime7());
        map.put("endTime8", dto.getEndTime8());
        map.put("endTime9", dto.getEndTime9());
        map.put("endTime10", dto.getEndTime10());
        map.put("endTime11", dto.getEndTime11());
        map.put("endTime12", dto.getEndTime12());
        map.put("endTime13", dto.getEndTime13());
        map.put("endTime14", dto.getEndTime14());
        map.put("thing1", dto.getThing1());
        map.put("thing2", dto.getThing2());
        map.put("thing3", dto.getThing3());
        map.put("thing4", dto.getThing4());
        map.put("thing5", dto.getThing5());
        map.put("thing6", dto.getThing6());
        map.put("thing6", dto.getThing7());

        UserDO userDO = ShiroUtils.getUser();
        dto.setStaffingId(userDO.getUserId());
        dto.setStaffingName(userDO.getName());
        dto.setWorkTimeMap(JSON.toJSONString(map));
        log.error("dto.getTableDate2()：{}",dto.getTableDate2());
//        log.error("dto.getTableDate()：{}",dto.getTableData());

        //前端组件弄不了时区，要后端转换
//        if (!ObjectUtils.isEmpty(dto.getTableDate2())){
//            String str = "[{\"id\":0,\"value1\":[\"2023-03-07T01:00:00.000Z\",\"2023-03-07T01:00:00.000Z\"],\"valuetime\":0,\"valuetime1\":0,\"value2\":[\"2023-03-07T08:00:00.000Z\",\"2023-03-07T08:00:00.000Z\"],\"valuething\":\"选项2\",\"valuegroup\":\"\"}]";

        List<WorkTimeVO> tableDate2 = JSON.parseArray(dto.getTableDate2(), WorkTimeVO.class);
//            for (WorkTimeVO timeVO : tableDate2) {
//                if (!ObjectUtils.isEmpty(timeVO.getValue2())){
//                    List<Date>   value2 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue2().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value2.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue2().get(1));
//                    calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value2.add(calendar2.getTime());
//                    timeVO.setValue2(value2);
//                }
//                if (!ObjectUtils.isEmpty(timeVO.getValue1())){
//                    List<Date>   value1 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue1().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value1.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue1().get(1));
//                    calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value1.add(calendar2.getTime());
//                    timeVO.setValue1(value1);
//                }
//            }

        dto.setWorkTimeMap2(JSON.toJSONString(tableDate2));

//        }


//        dto.setWorkTimeMap2(ObjectUtils.isEmpty(dto.getTableData()) ? null : JSON.toJSONString(dto.getTableData()));
        if(ObjectUtils.isEmpty(dto.getStatus())){
            dto.setStatus(AslConstant.MoldingDailyStatus.PLAN.getType());
        }

        //配置批号  yyMMddA-设备号
        dto.setBatchNo(getBatchNo(dto.getMGroup(), dto.getDeviceNo()));

        MoldingDailyDO entity = new MoldingDailyDO();
        SpringUtils.copyPropertiesIgnoreNull(dto, entity);
        int result = dao.save(entity);
        //给用户提示
//        List<Long> toUsers = new ArrayList<>();
//        toUsers.add(272l);
//        noticeService.sendCheckMessage(entity.getId(),toUsers,"成型日报新增提醒", "/jobShop/shapingDaily_add?id=","成型日报新增提醒");
        if (result > AslConstant.ZERO) {
            dto.setId(entity.getId());
            return result;
        }
        return AslConstant.ZERO;
    }

    //配置批号  yyMMddA-设备号
    private String getBatchNo(Integer group, String deviceNo) {
        //配置批号  yyMMdd_A_设备号
        //配置批号  yyMMddA-设备号
        Date date = new Date();
        String dateString = DateUtils.getDateByMilli(date.getTime());
        String groupString = "";
        switch (group) {
            case 0:
                groupString = "A";
                break;
            case 1:
                groupString = "B";
                break;
            case 2:
                groupString = "C";
                break;
        }
        String d = "-";
        return dateString.substring(0, 10).replaceAll(d, "") + groupString;
    }

    @Override
    public MoldingDailyDO get(Long id) {
        return dao.get(id);
    }

    @Override
    public Map<String, Object> getDetailInfo(Long id) {

        Map<String, Object> result = dao.getDetailInfo(id);

        Date indicateDate = (Date) result.get("indicateDate");
        Date startDate = (Date) result.get("startDate");
        Date endDate = (Date) result.get("endDate");

        result.put("indicateDate", DateUtils.format(indicateDate, DateUtils.DATE_TIME_PATTERN));
        result.put("startDate", DateUtils.format(startDate, DateUtils.DATE_TIME_PATTERN));
        result.put("endDate", DateUtils.format(endDate, DateUtils.DATE_TIME_PATTERN));

        //工作时间
        String workTimeMapJson = String.valueOf(result.get("workTimeMap"));
        String workTimeMapJson2 = String.valueOf(result.get("workTimeMap2"));

        List<WorkTimeVO> workTimeMap2 = ObjectUtils.isEmpty(workTimeMapJson2) ? null : JSON.parseArray(workTimeMapJson2, WorkTimeVO.class);
//        Map workTimeMap = JSON.parseObject(workTimeMapJson, Map.class);
//        result.putAll(workTimeMap);


        //前端展示的是世界时区，所以要转成世界时区 别问我为什么代码这么low，前端太菜只能动后端
        if (!ObjectUtils.isEmpty(workTimeMap2)){
            for (WorkTimeVO timeVO : workTimeMap2) {
                if (!ObjectUtils.isEmpty(timeVO.getValue2())  && !ObjectUtils.isEmpty(timeVO.getValue2().get(0))){
                    List<Date>   value2 = new ArrayList<>();
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(timeVO.getValue2().get(0));
                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 8);
                    value2.add(calendar.getTime());
                    Calendar calendar2 = Calendar.getInstance();
                    calendar2.setTime(timeVO.getValue2().get(1));
                    calendar2.set(Calendar.HOUR, calendar2.get(Calendar.HOUR) - 8);
                    value2.add(calendar2.getTime());
                    timeVO.setValue2(value2);
                }
                if (!ObjectUtils.isEmpty(timeVO.getValue1())  && !ObjectUtils.isEmpty(timeVO.getValue1().get(0))){
                    List<Date>   value1 = new ArrayList<>();
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(timeVO.getValue1().get(0));
                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 8);
                    value1.add(calendar.getTime());
                    Calendar calendar2 = Calendar.getInstance();
                    calendar2.setTime(timeVO.getValue1().get(1));
                    calendar2.set(Calendar.HOUR, calendar2.get(Calendar.HOUR) - 8);
                    value1.add(calendar2.getTime());
                    timeVO.setValue1(value1);
                }
            }
        }
        result.put("tableDate2",workTimeMap2);




        //原料投入量
        String feedingMaterialJson = JSONObject.toJSONString(result.get("feedingMaterial"));
        JSONArray feedingMaterial = new JSONArray();
        Object b = JSON.parse(feedingMaterialJson);
        if (!ObjectUtils.isEmpty(b)){
            Object c = JSON.parse(b.toString());
            feedingMaterial = JSON.parseArray(c.toString());
        }
        result.put("feedingMaterial", feedingMaterial);
        String feedingMaterialRealityJson = JSONObject.toJSONString(result.get("feedingMaterialReality"));
        JSONArray feedingMaterialReality = new JSONArray();
        Object b2 = JSON.parse(feedingMaterialRealityJson);
        if (!ObjectUtils.isEmpty(b)){
            Object c2 = JSON.parse(b2.toString());
            feedingMaterialReality = ObjectUtils.isEmpty(c2) ? null : JSON.parseArray(c2.toString());
        }
        result.put("feedingMaterialReality", feedingMaterialReality);
//        Object c = JSON.parse(b.toString());
//        JSONArray feedingMaterial = JSON.parseArray(c.toString());
//        result.put("feedingMaterial", feedingMaterial);
        if (result.containsKey("rawMaterialRatio") && !ObjectUtils.isEmpty(result.get("rawMaterialRatio"))){
            String str = (String)result.get("rawMaterialRatio");
            JSONObject ratio = JSON.parseObject(str);
            result.put("rawMaterialRatio", ratio);
        }

//        //成型生产指示
//        Map<String, Object> mpi = moldingProductionInstructionService
//            .getDetailInfo((Long) result.get("mpiId"));
//        result.put("mpi", mpi);
        //成型生产指示
        Map<String, Object> mpi = moldingProductionInstructionService
                .getDetailInfoTwo((Long) result.get("mpiId"));
        result.put("mpi", mpi);

        //不良现况
        String badSituationJson = String.valueOf(result.get("badSituation"));
        JSONArray badSituation = JSON.parseArray(badSituationJson);
        result.put("badSituation", badSituation);

        //未达要因
        String failedReachJson = String.valueOf(result.get("failedReach"));
        JSONArray failedReach = JSON.parseArray(failedReachJson);
        result.put("failedReach", failedReach);

        //成型设备重要参数
        String importantParametersMoldingEquipmentJson = String
                .valueOf(result.get("importantParametersMoldingEquipment"));
        Map<String, Object> importantParametersMoldingEquipment = JSON
                .parseObject(importantParametersMoldingEquipmentJson);
        result.put("importantParametersMoldingEquipment", importantParametersMoldingEquipment);

        //设备异常现况
        String equipmentAbnormalStatusJson = String.valueOf(result.get("equipmentAbnormalStatus"));
        JSONArray equipmentAbnormalStatus = JSON.parseArray(equipmentAbnormalStatusJson);
        result.put("equipmentAbnormalStatus", equipmentAbnormalStatus);

        return result;
    }

    @Override
    public Integer update(MoldingDailyDO entity) {
        return dao.update(entity);
    }

    @Override
    public Integer update(MoldingDailyDto dto) {
        Map<String, String> map = new HashMap<>();
        map.put("startTime1", dto.getStartTime1());
        map.put("startTime2", dto.getStartTime2());
        map.put("startTime3", dto.getStartTime3());
        map.put("startTime4", dto.getStartTime4());
        map.put("startTime5", dto.getStartTime5());
        map.put("startTime6", dto.getStartTime6());
        map.put("startTime7", dto.getStartTime7());
        map.put("startTime8", dto.getStartTime8());
        map.put("startTime9", dto.getStartTime9());
        map.put("startTime10", dto.getStartTime10());
        map.put("startTime11", dto.getStartTime11());
        map.put("startTime12", dto.getStartTime12());
        map.put("startTime13", dto.getStartTime13());
        map.put("startTime14", dto.getStartTime14());
        map.put("endTime1", dto.getEndTime1());
        map.put("endTime2", dto.getEndTime2());
        map.put("endTime3", dto.getEndTime3());
        map.put("endTime4", dto.getEndTime4());
        map.put("endTime5", dto.getEndTime5());
        map.put("endTime6", dto.getEndTime6());
        map.put("endTime7", dto.getEndTime7());
        map.put("endTime8", dto.getEndTime8());
        map.put("endTime9", dto.getEndTime9());
        map.put("endTime10", dto.getEndTime10());
        map.put("endTime11", dto.getEndTime11());
        map.put("endTime12", dto.getEndTime12());
        map.put("endTime13", dto.getEndTime13());
        map.put("endTime14", dto.getEndTime14());
        map.put("thing1", dto.getThing1());
        map.put("thing2", dto.getThing2());
        map.put("thing3", dto.getThing3());
        map.put("thing4", dto.getThing4());
        map.put("thing5", dto.getThing5());
        map.put("thing6", dto.getThing6());
        map.put("thing6", dto.getThing7());

        //前端组件弄不了时区，要后端转换
        if (!ObjectUtils.isEmpty(dto.getTableDate2())){

            List<WorkTimeVO> tableDate2 = JSON.parseArray(dto.getTableDate2(), WorkTimeVO.class);
//            for (WorkTimeVO timeVO : tableDate2) {
//                if (!ObjectUtils.isEmpty(timeVO.getValue2())){
//                    List<Date>   value2 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue2().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value2.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue2().get(1));
//                    calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value2.add(calendar2.getTime());
//                    timeVO.setValue2(value2);
//                }
//                if (!ObjectUtils.isEmpty(timeVO.getValue1())){
//                    List<Date>   value1 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue1().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value1.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue1().get(1));
//                    calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value1.add(calendar2.getTime());
//                    timeVO.setValue1(value1);
//                }
//            }

            dto.setWorkTimeMap2(JSON.toJSONString(tableDate2));

        }
//        dto.setWorkTimeMap2(ObjectUtils.isEmpty(tableData) ? null : JSON.toJSONString(tableData));
        dto.setWorkTimeMap(JSON.toJSONString(map));
        MoldingDailyDO entity = new MoldingDailyDO();
        SpringUtils.copyPropertiesIgnoreNull(dto, entity);

        if (ObjectUtils.isEmpty(entity.getEquipmentAbnormalStatus())) entity.setEquipmentAbnormalStatus("[]");
        int result = dao.update(entity);
        //给用户提示
        List<Long> toUsers = new ArrayList<>();
        toUsers.add(272l);
//        if(!AslConstant.MoldingDailyStatus.SUBMITTED.getType().equals(dto.getStatus())){
//            noticeService.sendCheckMessage(entity.getId(),toUsers,"成型日报修改提醒", "/jobShop/shapingDaily_add?id=","成型日报修改提醒");
//        }
        if (result > AslConstant.ZERO) {
            return result;
        }
        return AslConstant.ZERO;
    }

    public static void main(String[] args) {
        String str = "[{\"id\":0,\"value1\":[\"2023-03-07T01:00:00.000Z\",\"2023-03-07T01:00:00.000Z\"],\"valuetime\":0,\"valuetime1\":0,\"value2\":[\"2023-03-07T08:00:00.000Z\",\"2023-03-07T08:00:00.000Z\"],\"valuething\":\"选项2\",\"valuegroup\":\"\"}]";
        List<WorkTimeVO> tableDate2 = JSON.parseArray(str, WorkTimeVO.class);
        for (WorkTimeVO timeVO : tableDate2) {
            if (!ObjectUtils.isEmpty(timeVO.getValue2())  && !ObjectUtils.isEmpty(timeVO.getValue2().get(0))){
                List<Date>   value2 = new ArrayList<>();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(timeVO.getValue2().get(0));
                calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
                value2.add(calendar.getTime());
                Calendar calendar2 = Calendar.getInstance();
                calendar2.setTime(timeVO.getValue2().get(1));
                calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
                value2.add(calendar2.getTime());
                timeVO.setValue2(value2);
            }
            if (!ObjectUtils.isEmpty(timeVO.getValue1())  && !ObjectUtils.isEmpty(timeVO.getValue1().get(0))){
                List<Date>   value1 = new ArrayList<>();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(timeVO.getValue1().get(0));
                calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
                value1.add(calendar.getTime());
                Calendar calendar2 = Calendar.getInstance();
                calendar2.setTime(timeVO.getValue1().get(1));
                calendar2.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
                value1.add(calendar2.getTime());
                timeVO.setValue1(value1);
            }
        }
    }
    @Override
    public Integer syncSaveToK3(MoldingDailyDO entity) {
        String group = entity.getMGroup().equals(0) ? "A" : (entity.getMGroup().equals(1) ? "B" : "C");
        String batch = DateUtil.format(new Date(), "yyyyMMdd") + group;
        //生产任务单id
//        MoldingProductionInstructionDO moldingProductionInstructionDO = moldingProductionInstructionService
//            .get(entity.getMpiId());
        Map<String, Object> moldingProductionInstructionDO = moldingProductionInstructionService.getDetail(entity.getMpiId());
        MoldingDailyDO dailyDO = dao.get(entity.getId());
        Object planId = moldingProductionInstructionDO.get("planId");
        if (ObjectUtils.isEmpty(planId)){
            log.error("未找到生产指示的生产计划，不同步金蝶===========================");
            return 0;
        }
        Map<String, Object> moldingProductionInstructionDO2 = moldingProductionInstructionService.getDetail(entity.getMpiId2());
        Object planId2 = moldingProductionInstructionDO2.get("planId");
        if (ObjectUtils.isEmpty(planId2)){
            log.error("未找到生产指示2的生产计划，不同步金蝶===========================");
            return 0;
        }

        UserDO userDO = userService.get(dailyDO.getCreateBy());
        HashMap<String, Object> map = new HashMap<>();
        ArrayList planIds = new ArrayList();
        planIds.add(planId);
        map.put("planIds",planIds);
        List<ProductionFeedingDetailDO> feedingDetails = productionFeedingDetailDao.feedingItemList(map);
        Map<Long, ProductionFeedingDetailDO> detailDOMap = feedingDetails.stream().collect(Collectors.toMap(ProductionFeedingDetailDO::getMaterielId, v -> v, (v1, v2) -> v1));

        HashMap<String, Object> map2 = new HashMap<>();
        ArrayList planIds2 = new ArrayList();
        planIds2.add(planId2);
        map2.put("planIds",planIds2);
        List<ProductionFeedingDetailDO> feedingDetails2 = productionFeedingDetailDao.feedingItemList(map2);
        Map<Long, ProductionFeedingDetailDO> detailDOMap2 = feedingDetails2.stream().collect(Collectors.toMap(ProductionFeedingDetailDO::getMaterielId, v -> v, (v1, v2) -> v1));



        //原料理论投入量1
        String feedingMaterialRealityJson = entity.getFeedingMaterial();
        //原料理论投入量2
        String feedingMaterialRealityJson2 = entity.getFeedingMaterial2();
        //原料实际投入量
//        String feedingMaterialRealityJson = entity.getFeedingMaterialReality();
        JSONArray feedingMaterialfeedingMaterialRealityJson = JSON.parseArray(feedingMaterialRealityJson);
        StockInDO stockIn = new StockInDO();
        stockIn.setOperator(ShiroUtils.getUserId());
        stockIn.setSourceCompany(ShiroUtils.getUser().getDeptId());
        StockOutDO stockOut = new StockOutDO();
        stockOut.setOperator(ShiroUtils.getUserId());
        List<Object> feedingTrueMaterial = feedingMaterialfeedingMaterialRealityJson.stream().filter(feeding -> {
            JSONObject jsonObject = (JSONObject) feeding;
            return (StringUtils.isNotBlank(jsonObject.getString("materielId"))
                    && StringUtils.isNotBlank(jsonObject.getString("count"))
                    && new BigDecimal(jsonObject.getString("count")).compareTo(BigDecimal.ZERO) > 0);
        }).collect(Collectors.toList());
        String msg = "";

        JSONArray feedingMaterialfeedingMaterialRealityJson2 = JSON.parseArray(feedingMaterialRealityJson2);
        StockInDO stockIn2 = new StockInDO();
        stockIn2.setOperator(ShiroUtils.getUserId());
        stockIn2.setSourceCompany(ShiroUtils.getUser().getDeptId());
        StockOutDO stockOut2 = new StockOutDO();
        stockOut2.setOperator(ShiroUtils.getUserId());
        List<Object> feedingTrueMaterial2 = feedingMaterialfeedingMaterialRealityJson2.stream().filter(feeding -> {
            JSONObject jsonObject = (JSONObject) feeding;
            return (StringUtils.isNotBlank(jsonObject.getString("materielId"))
                    && StringUtils.isNotBlank(jsonObject.getString("count"))
                    && new BigDecimal(jsonObject.getString("count")).compareTo(BigDecimal.ZERO) > 0);
        }).collect(Collectors.toList());

        ArrayList<SyncLogDO> syncLogDOS = new ArrayList<>();
        //原料投入量 领料车间库
        if (!ObjectUtils.isEmpty(feedingTrueMaterial)){
            log.error("==========================查询库存======================================");
            String filter = "and 仓库ID='" + Constant.warehouse2 + "'";
            Triple<Boolean, String, List<KisReceiveStockVo>> stockList = kisBasicsService.realTimeStockBalanceEnquiry2(filter);
            if (!stockList.getLeft()){
                msg = stockList.getMiddle();
                log.error("==========================查询库存失败======================================");
                throw new BDException(msg);
            }

            List<KisReceiveStockVo> stockVos = stockList.getRight();
            log.error("==========================stockVos======================================");
            log.error(JSON.toJSONString(stockVos));
            Map<String, List<KisReceiveStockVo>> stockGroupByStock = stockVos.stream()
                    .filter(s ->!ObjectUtils.isEmpty(s) && !ObjectUtils.isEmpty(s.getFQty()) && new BigDecimal(s.getFQty()).compareTo(BigDecimal.ZERO) >0).collect(Collectors.groupingBy(i-> i.getFStockID()+"_"+i.getFItemID()));
            Map<String, BigDecimal> totalGroupByStock = stockVos.stream().filter(s ->!ObjectUtils.isEmpty(s) && !ObjectUtils.isEmpty(s.getFQty()) && new BigDecimal(s.getFQty()).compareTo(BigDecimal.ZERO) >0)
                    .collect(Collectors.groupingBy(i-> i.getFStockID()+"_"+i.getFItemID(), CustomCollectors.summingBigDecimal(i -> new BigDecimal(i.getFQty()))));
            List<StockOutItemDO> itemList = new ArrayList<>();
            for (int i=0; i<feedingTrueMaterial.size(); i++){
                JSONObject jsonObject = (JSONObject) feedingTrueMaterial.get(i);
                Long materielId = new Long(jsonObject.getString("materielId"));
                if(materielId == 1857){
                    log.error("==========================边角料无需领料，跳过======================================");
                    continue;
                }
                BigDecimal count = new BigDecimal(jsonObject.getString("count"));
                List<KisReceiveStockVo> kisReceiveStockVos = stockGroupByStock.get(Constant.warehouse2+"_"+materielId);
                BigDecimal total = totalGroupByStock.get(Constant.warehouse2+"_"+materielId);
                if (ObjectUtils.isEmpty(kisReceiveStockVos) || total.compareTo(count)<0){
                    log.error("==========================stockGroupByStock：{}",JSON.toJSONString(stockGroupByStock));
                    log.error("==========================totalGroupByStock：{}",JSON.toJSONString(totalGroupByStock));
                    log.error("==========================kisReceiveStockVos: {}",JSON.toJSONString(kisReceiveStockVos));
                    log.error("==========================total: {}",total);
                    log.error("==========================count: {}",count);
                    MaterielDO materielDO = materielService.get(materielId);
                    FacilityDO facilityDO = facilityService.get(Constant.warehouse2);
                    String materielName = ObjectUtils.isEmpty(materielDO) ? materielId.toString() : materielDO.getName();
                    String facilityName = ObjectUtils.isEmpty(facilityDO) ? Constant.warehouse2.toString() : facilityDO.getName();
                    throw new BDException("物料"+ materielName +"在仓库"+facilityName+"的库存不足，不能领料");
                }
                ProductionFeedingDetailDO detailDO = detailDOMap.get(materielId);
                BigDecimal residue = new BigDecimal(jsonObject.getString("count"));
                for (int j=0; j<kisReceiveStockVos.size(); j++){
                    KisReceiveStockVo stockVo = kisReceiveStockVos.get(j);
                    BigDecimal fQty = new BigDecimal(stockVo.getFQty());
                    if (fQty.compareTo(BigDecimal.ZERO) <= 0) continue;
                    log.error("==========================fQty: {}",fQty);
                    log.error("==========================residue: {}",residue);
                    if (fQty.compareTo(residue) >=0){
                        StockOutItemDO itemDO = new StockOutItemDO();
                        itemDO.setMaterielId(materielId);
                        itemDO.setWarehouse(Constant.warehouse2);//车间仓库
                        itemDO.setWarehLocation(new Long(stockVo.getFStockPlaceID()));
                        itemDO.setCount(residue);
                        log.error("==========================领料residue: {}",residue);
                        itemDO.setSourceInteridEntryid(detailDO.getInteridEntryid());
                        itemDO.setSourceCode(detailDO.getFeedingNo());
                        itemDO.setBatch(stockVo.getFBatchNo());
                        itemDO.setUuid(UUID.randomUUID().toString());
                        itemList.add(itemDO);
                        break;
                    }else {
                        StockOutItemDO itemDO = new StockOutItemDO();
                        itemDO.setMaterielId(materielId);
                        itemDO.setWarehouse(Constant.warehouse2);//车间仓库
                        itemDO.setWarehLocation(new Long(stockVo.getFStockPlaceID()));
                        itemDO.setCount(fQty);
                        log.error("==========================领料fQty: {}",fQty);
                        itemDO.setSourceInteridEntryid(detailDO.getInteridEntryid());
                        itemDO.setSourceCode(detailDO.getFeedingNo());
                        itemDO.setBatch(stockVo.getFBatchNo());
                        itemDO.setUuid(UUID.randomUUID().toString());
                        itemList.add(itemDO);
                        residue = residue.subtract(fQty);
                    }
                }
            }
            log.error("==========================原料投入量 领料车间库======================================");
            log.error("stockOut:======"+stockOut2);
            log.error("itemList:======"+itemList);
            Triple<Boolean, String, String> triple = this.outConversionSync2(stockOut2, itemList, userDO);
            if (!triple.getLeft()) {
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3LinLiao2(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                throw new BDException(checkResult.getMiddle());
            }
            SyncLogDO syncLogDO = new SyncLogDO();
            String content = "成型日报领料单据编号："+triple.getRight()+"需要反审核";
            syncLogDO.setType(1);
            syncLogDO.setContent(content);
            syncLogDOS.add(syncLogDO);
        }
        //原料投入量 领料车间库2
        if (!ObjectUtils.isEmpty(feedingTrueMaterial2)){
            log.error("==========================查询库存======================================");
            String filter = "and 仓库ID='" + Constant.warehouse2 + "'";
            Triple<Boolean, String, List<KisReceiveStockVo>> stockList = kisBasicsService.realTimeStockBalanceEnquiry2(filter);
            if (!stockList.getLeft()){
                msg = stockList.getMiddle();
                log.error("==========================查询库存失败======================================");
                throw new BDException(msg);
            }

            List<KisReceiveStockVo> stockVos = stockList.getRight();
            log.error("==========================stockVos======================================");
            log.error(JSON.toJSONString(stockVos));
            Map<String, List<KisReceiveStockVo>> stockGroupByStock = stockVos.stream()
                    .filter(s ->!ObjectUtils.isEmpty(s) && !ObjectUtils.isEmpty(s.getFQty()) && new BigDecimal(s.getFQty()).compareTo(BigDecimal.ZERO) >0).collect(Collectors.groupingBy(i-> i.getFStockID()+"_"+i.getFItemID()));
            Map<String, BigDecimal> totalGroupByStock = stockVos.stream().filter(s ->!ObjectUtils.isEmpty(s) && !ObjectUtils.isEmpty(s.getFQty()) && new BigDecimal(s.getFQty()).compareTo(BigDecimal.ZERO) >0)
                    .collect(Collectors.groupingBy(i-> i.getFStockID()+"_"+i.getFItemID(), CustomCollectors.summingBigDecimal(i -> new BigDecimal(i.getFQty()))));
            List<StockOutItemDO> itemList = new ArrayList<>();
            for (int i=0; i<feedingTrueMaterial2.size(); i++){
                JSONObject jsonObject = (JSONObject) feedingTrueMaterial2.get(i);
                Long materielId = new Long(jsonObject.getString("materielId"));
                if(materielId == 1857){
                    log.error("==========================边角料无需领料，跳过======================================");
                    continue;
                }
                BigDecimal count = new BigDecimal(jsonObject.getString("count"));
                List<KisReceiveStockVo> kisReceiveStockVos = stockGroupByStock.get(Constant.warehouse2+"_"+materielId);
                BigDecimal total = totalGroupByStock.get(Constant.warehouse2+"_"+materielId);
                if (ObjectUtils.isEmpty(kisReceiveStockVos) || total.compareTo(count)<0){
                    log.error("==========================stockGroupByStock：{}",JSON.toJSONString(stockGroupByStock));
                    log.error("==========================totalGroupByStock：{}",JSON.toJSONString(totalGroupByStock));
                    log.error("==========================kisReceiveStockVos: {}",JSON.toJSONString(kisReceiveStockVos));
                    log.error("==========================total: {}",total);
                    log.error("==========================count: {}",count);
                    MaterielDO materielDO = materielService.get(materielId);
                    FacilityDO facilityDO = facilityService.get(Constant.warehouse2);
                    String materielName = ObjectUtils.isEmpty(materielDO) ? materielId.toString() : materielDO.getName();
                    String facilityName = ObjectUtils.isEmpty(facilityDO) ? Constant.warehouse2.toString() : facilityDO.getName();
                    throw new BDException("物料"+ materielName +"在仓库"+facilityName+"的库存不足，不能领料");
                }
                ProductionFeedingDetailDO detailDO = detailDOMap2.get(materielId);
                BigDecimal residue = new BigDecimal(jsonObject.getString("count"));
                for (int j=0; j<kisReceiveStockVos.size(); j++){
                    KisReceiveStockVo stockVo = kisReceiveStockVos.get(j);
                    BigDecimal fQty = new BigDecimal(stockVo.getFQty());
                    if (fQty.compareTo(BigDecimal.ZERO) <= 0) continue;
                    log.error("==========================fQty: {}",fQty);
                    log.error("==========================residue: {}",residue);
                    if (fQty.compareTo(residue) >=0){
                        StockOutItemDO itemDO = new StockOutItemDO();
                        itemDO.setMaterielId(materielId);
                        itemDO.setWarehouse(Constant.warehouse2);//车间仓库
                        itemDO.setWarehLocation(new Long(stockVo.getFStockPlaceID()));
                        itemDO.setCount(residue);
                        log.error("==========================领料residue: {}",residue);
                        itemDO.setSourceInteridEntryid(detailDO.getInteridEntryid());
                        itemDO.setSourceCode(detailDO.getFeedingNo());
                        itemDO.setBatch(stockVo.getFBatchNo());
                        itemDO.setUuid(UUID.randomUUID().toString());
                        itemList.add(itemDO);
                        break;
                    }else {
                        StockOutItemDO itemDO = new StockOutItemDO();
                        itemDO.setMaterielId(materielId);
                        itemDO.setWarehouse(Constant.warehouse2);//车间仓库
                        itemDO.setWarehLocation(new Long(stockVo.getFStockPlaceID()));
                        itemDO.setCount(fQty);
                        log.error("==========================领料fQty: {}",fQty);
                        itemDO.setSourceInteridEntryid(detailDO.getInteridEntryid());
                        itemDO.setSourceCode(detailDO.getFeedingNo());
                        itemDO.setBatch(stockVo.getFBatchNo());
                        itemDO.setUuid(UUID.randomUUID().toString());
                        itemList.add(itemDO);
                        residue = residue.subtract(fQty);
                    }
                }
            }
            log.error("==========================原料投入量 领料车间库======================================");
            log.error("stockOut:======"+stockOut2);
            log.error("itemList:======"+itemList);
            Triple<Boolean, String, String> triple = this.outConversionSync2(stockOut2, itemList, userDO);
            if (!triple.getLeft()) {
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3LinLiao2(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                throw new BDException(checkResult.getMiddle());
            }
            SyncLogDO syncLogDO = new SyncLogDO();
            String content = "成型日报领料单据编号："+triple.getRight()+"需要反审核";
            syncLogDO.setType(1);
            syncLogDO.setContent(content);
            syncLogDOS.add(syncLogDO);
        }

        //不良数量1 入库不良品库
        if (!ObjectUtils.isEmpty(dailyDO.getInspectionQty()) && dailyDO.getInspectionQty().compareTo(BigDecimal.ZERO) > 0){
            List<StockInItemDO> qualifiedCollect = new ArrayList<>();
            StockInItemDO itemDO = new StockInItemDO();
            itemDO.setMaterielId((Long)moldingProductionInstructionDO.get("materielId"));
            itemDO.setWarehouse(Constant.warehouse3);
            itemDO.setCount(dailyDO.getInspectionQty());
            itemDO.setSourceInteridEntryid(moldingProductionInstructionDO.get("planId").toString());
            itemDO.setBatch(DateUtil.format(new Date(), "yyyyMMdd")+"D1");
            itemDO.setSourceCode(moldingProductionInstructionDO.get("planNo").toString());
            itemDO.setUuid(UUID.randomUUID().toString());
            qualifiedCollect.add(itemDO);
            log.info("==========================不良数量1 入库不良品库======================================");
            log.info("==========================合格数量：userDO:{}======================================",userDO);
            Triple<Boolean, String, String> triple = kisBillOfPushService.inputTypeParamConversionSync2(1, 2, qualifiedCollect,stockIn, userDO);
            if (!triple.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3In(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(checkResult.getMiddle());
            }
            SyncLogDO syncLogDO = new SyncLogDO();
            String content = "成型日报不良品1入库单据编号："+triple.getRight()+"需要反审核";
            syncLogDO.setContent(content);
            syncLogDO.setType(2);
            syncLogDOS.add(syncLogDO);
        }
        //不良数量2 入库不良品库
        if (!ObjectUtils.isEmpty(dailyDO.getInspectionQty2()) && dailyDO.getInspectionQty2().compareTo(BigDecimal.ZERO) > 0){
            List<StockInItemDO> qualifiedCollect = new ArrayList<>();
            StockInItemDO itemDO = new StockInItemDO();
            itemDO.setMaterielId((Long)moldingProductionInstructionDO2.get("materielId"));
            itemDO.setWarehouse(Constant.warehouse3);
            itemDO.setCount(dailyDO.getInspectionQty2());
            itemDO.setSourceInteridEntryid(moldingProductionInstructionDO2.get("planId").toString());
            itemDO.setBatch(DateUtil.format(new Date(), "yyyyMMdd")+"D2");
            itemDO.setSourceCode(moldingProductionInstructionDO2.get("planNo").toString());
            itemDO.setUuid(UUID.randomUUID().toString());
            qualifiedCollect.add(itemDO);
            log.info("==========================不良数量2 入库不良品库======================================");
            log.info("==========================合格数量：userDO:{}======================================",userDO);
            Triple<Boolean, String, String> triple = kisBillOfPushService.inputTypeParamConversionSync2(1, 2, qualifiedCollect,stockIn2, userDO);
            if (!triple.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3In(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(checkResult.getMiddle());
            }
            SyncLogDO syncLogDO = new SyncLogDO();
            String content = "成型日报不良品2入库单据编号："+triple.getRight()+"需要反审核";
            syncLogDO.setContent(content);
            syncLogDO.setType(2);
            syncLogDOS.add(syncLogDO);
        }
        //不良数量3 入库不良品库
        if (!ObjectUtils.isEmpty(dailyDO.getInspectionQty3()) && dailyDO.getInspectionQty3().compareTo(BigDecimal.ZERO) > 0){
            List<StockInItemDO> qualifiedCollect = new ArrayList<>();
            StockInItemDO itemDO = new StockInItemDO();
            itemDO.setMaterielId((Long)moldingProductionInstructionDO2.get("materielId"));
            itemDO.setWarehouse(Constant.warehouse3);
            itemDO.setCount(dailyDO.getInspectionQty3());
            itemDO.setSourceInteridEntryid(moldingProductionInstructionDO2.get("planId").toString());
            itemDO.setBatch(DateUtil.format(new Date(), "yyyyMMdd")+"D3");
            itemDO.setSourceCode(moldingProductionInstructionDO2.get("planNo").toString());
            itemDO.setUuid(UUID.randomUUID().toString());
            qualifiedCollect.add(itemDO);
            log.info("==========================不良数量3 入库不良品库======================================");
            log.info("==========================合格数量：userDO:{}======================================",userDO);
            Triple<Boolean, String, String> triple = kisBillOfPushService.inputTypeParamConversionSync2(1, 2, qualifiedCollect,stockIn2, userDO);
            if (!triple.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3In(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(checkResult.getMiddle());
            }
            SyncLogDO syncLogDO = new SyncLogDO();
            String content = "成型日报不良品3入库单据编号："+triple.getRight()+"需要反审核";
            syncLogDO.setContent(content);
            syncLogDO.setType(2);
            syncLogDOS.add(syncLogDO);
        }

        //合格数量：入库车间库
        if (!ObjectUtils.isEmpty(dailyDO.getProductionQty()) && dailyDO.getProductionQty().compareTo(BigDecimal.ZERO) > 0){
            List<StockInItemDO> qualifiedCollect = new ArrayList<>();
            StockInItemDO itemDO = new StockInItemDO();
            itemDO.setMaterielId((Long)moldingProductionInstructionDO.get("materielId"));
            itemDO.setWarehouse(Constant.warehouse4);//成品库
//            itemDO.setWarehLocation(Constant.warehLocation4);//批号
            itemDO.setCount(dailyDO.getProductionQty().subtract(dailyDO.getTotalReportedWork() == null? BigDecimal.ZERO : dailyDO.getTotalReportedWork()));
            if(itemDO.getCount().compareTo(BigDecimal.ZERO) > 0){ //数量大于0才入库
                itemDO.setSourceInteridEntryid(moldingProductionInstructionDO.get("planId").toString());
                itemDO.setBatch(batch);
                itemDO.setSourceCode(moldingProductionInstructionDO.get("planNo").toString());
                itemDO.setUuid(UUID.randomUUID().toString());
                qualifiedCollect.add(itemDO);
                log.error("==========================合格数量：入库车间库======================================");
                log.error("==========================合格数量：userDO:{}======================================",userDO);
                Triple<Boolean, String, String> triple = kisBillOfPushService.inputTypeParamConversionSync2(1, 2, qualifiedCollect,stockIn, userDO);
                if (!triple.getLeft()) {
                    productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                    throw new BDException(triple.getMiddle());
                }
                Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3In(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
                if (!checkResult.getLeft()) {
                    productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                    throw new BDException(triple.getMiddle());
                }
            }

        }

        //边角料数量：入库车间库
        if (!ObjectUtils.isEmpty(dailyDO.getLeftoverMaterial()) && dailyDO.getLeftoverMaterial().compareTo(BigDecimal.ZERO) > 0){
            List<StockInItemDO> qualifiedCollect = new ArrayList<>();
            StockInItemDO itemDO = new StockInItemDO();
            itemDO.setMaterielId(Constant.BJL);//边角料id
            itemDO.setWarehouse(Constant.warehouse4);//成品库
//            itemDO.setWarehLocation(Constant.warehLocation4);//批号
            itemDO.setCount(dailyDO.getLeftoverMaterial());
            itemDO.setSourceInteridEntryid(moldingProductionInstructionDO.get("planId").toString());
            itemDO.setBatch(DateUtil.format(new Date(), "yyyyMMdd")+"D4");
            itemDO.setSourceCode(moldingProductionInstructionDO.get("planNo").toString());
            itemDO.setUuid(UUID.randomUUID().toString());
            qualifiedCollect.add(itemDO);
            log.error("==========================边角料数量：入库车间库======================================");
            log.error("==========================边角料数量：userDO:{}======================================",userDO);
            Triple<Boolean, String, String> triple = kisBillOfPushService.inputTypeParamConversionSync2(1, 2, qualifiedCollect,stockIn, userDO);
            if (!triple.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(triple.getMiddle());
            }
            Triple<Boolean, String, ApiResultVO2S> checkResult = kisBillOfPushService.checkK3In(ShiroUtils.getUser().getToken(), triple.getRight(), ShiroUtils.getUser().getName(),true);
            if (!checkResult.getLeft()) {
                productionFeedingDetailDao.batchSaveSyncLog(syncLogDOS);
                throw new BDException(triple.getMiddle());
            }
        }

//        //调用接口，传递生产任务汇报单、K3产品入库单、水口料红字领料单、生产领料单
//        String result = kingdeeMiddlewareService.saveSync(JSON.toJSONString(param));
//        JSONObject resultObj = JSON.parseObject(result);
//        if (!resultObj.getString("code").equals("0")) {
//            log.info(resultObj.getString("msg"));
//            return AslConstant.ZERO;
//        }
        return AslConstant.ONE;
//        return AslConstant.ZERO;
    }

    /**
     * 领料
     * @param stockOutDO
     * @param itemDOs
     * @return
     */
    public Triple<Boolean, String, String> outConversionSync(StockOutDO stockOutDO, List<StockOutItemDO> itemDOs){
        DictionaryDO storageType = dictionaryService.get(ConstantForGYL.LYCK);
        Long storageTypeId = storageType.getId();
        Triple<Boolean, String, String> triple = kisBillOfPushService.outTypeParamConversionSync2( 1, 24, itemDOs, stockOutDO);
        return triple;
    }

    /**
     * 领料
     * @param stockOutDO
     * @param itemDOs
     * @return
     */
    public Triple<Boolean, String, String> outConversionSync2(StockOutDO stockOutDO, List<StockOutItemDO> itemDOs, UserDO userDO){
        DictionaryDO storageType = dictionaryService.get(ConstantForGYL.LYCK);
        Long storageTypeId = storageType.getId();
        Triple<Boolean, String, String> triple = kisBillOfPushService.outTypeParamConversionSync2( 1, 24, itemDOs, stockOutDO,userDO);
        return triple;
    }

    @Override
    public int batchRemove(Long[] ids) {
        return dao.batchRemove(ids);
    }

    @Override
    public int remove(Long id) {
        return dao.remove(id);
    }

    @Override
    public int countForMap(Map<String, Object> params) {
        return dao.countForMap(params);
    }

    @Override
    public List<Map<String, Object>> listForMap(Map<String, Object> param) {
        return dao.listForMap(param);
    }

    @Override
    public int totalForMap(Map<String, Object> param) {
        return dao.totalForMap(param);
    }

    @Override
    public void downloadExport(HttpServletResponse response, Long id) {
        Map<String, Object> result = dao.getDetailInfo(id);
        HashMap<String, Object> mapResult = new HashMap<>();
        Date indicateDate = (Date) result.get("indicateDate");
        Date startDate = (Date) result.get("startDate");
        Date endDate = (Date) result.get("endDate");

        result.put("indicateDate", DateUtils.format(indicateDate, DateUtils.DATE_TIME_PATTERN));
        result.put("startDate", DateUtils.format(startDate, DateUtils.DATE_TIME_PATTERN));
        result.put("endDate", DateUtils.format(endDate, DateUtils.DATE_TIME_PATTERN));
        //日期
        mapResult.put("dateTime", DateUtils.format(startDate, DateUtils.DATE_TIME_PATTERN_TWO)  +" "+ DateUtils.format(endDate, DateUtils.DATE_TIME_PATTERN_TWO));
        //工作时间
        String workTimeMapJson = String.valueOf(result.get("workTimeMap"));
        String workTimeMapJson2 = String.valueOf(result.get("workTimeMap2"));

        List<WorkTimeVO> workTimeMap2 = ObjectUtils.isEmpty(workTimeMapJson2) ? null : JSON.parseArray(workTimeMapJson2, WorkTimeVO.class);
//        Map workTimeMap = JSON.parseObject(workTimeMapJson, Map.class);
//        result.putAll(workTimeMap);


        //前端展示的是世界时区，所以要转成世界时区
//        if (!ObjectUtils.isEmpty(workTimeMap2)) {
//            for (WorkTimeVO timeVO : workTimeMap2) {
//                if (!ObjectUtils.isEmpty(timeVO.getValue2()) && !ObjectUtils.isEmpty(timeVO.getValue2().get(0))) {
//                    List<Date> value2 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue2().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value2.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue2().get(1));
//                    calendar2.set(Calendar.HOUR, calendar2.get(Calendar.HOUR) + 8);
//                    value2.add(calendar2.getTime());
//                    timeVO.setValue2(value2);
//                }
//                if (!ObjectUtils.isEmpty(timeVO.getValue1()) && !ObjectUtils.isEmpty(timeVO.getValue1().get(0))) {
//                    List<Date> value1 = new ArrayList<>();
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(timeVO.getValue1().get(0));
//                    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
//                    value1.add(calendar.getTime());
//                    Calendar calendar2 = Calendar.getInstance();
//                    calendar2.setTime(timeVO.getValue1().get(1));
//                    calendar2.set(Calendar.HOUR, calendar2.get(Calendar.HOUR) + 8);
//                    value1.add(calendar2.getTime());
//                    timeVO.setValue1(value1);
//                }
//            }
//        }
        result.put("tableDate2", workTimeMap2);
        List<WorkTimeDO> listTime = new ArrayList();
        String valueThing = "";
        String valuethingName = "";
        Long totalAllTime = 0l;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d H:mm");
        for (WorkTimeVO item : workTimeMap2) {
            WorkTimeDO workTimeDO = new WorkTimeDO();
            if(!ObjectUtils.isEmpty(item.getValue1())){
                workTimeDO.setWorkTime1(item.getValue1().size() == 1 || ObjectUtils.isEmpty(item.getValue1().get(0)) ? null : sdf.format(item.getValue1().get(0)));
                workTimeDO.setWorkTime2(item.getValue1().size() == 1 || ObjectUtils.isEmpty(item.getValue1().get(1))  ? null : sdf.format(item.getValue1().get(1)));
            }
            if(!ObjectUtils.isEmpty(item.getValue2())){
                workTimeDO.setNoworkTime1(item.getValue2().size() == 1 || ObjectUtils.isEmpty(item.getValue2().get(0)) ? null : sdf.format(item.getValue2().get(0)));
                workTimeDO.setNoworkTime2(item.getValue2().size() == 1 || ObjectUtils.isEmpty(item.getValue2().get(1)) ? null : sdf.format(item.getValue2().get(1)));
            }
//            workTimeDO.setNoworkTime2(item.getValue2().size() == 1 ? null : sdf.format(Date.parse(item.getValue2().get(1).toString())));
//            workTimeDO.setWorkTime1(item.getValue1().size() == 1 ? null : sdf.format(Date.parse(item.getValue1().get(0).toString())));
//            workTimeDO.setWorkTime2(item.getValue1().size() == 1 ? null : sdf.format(Date.parse(item.getValue1().get(1).toString())));
//            workTimeDO.setNoworkTime1(item.getValue2().size() == 1 ? null : sdf.format(Date.parse(item.getValue2().get(0).toString())));
//            workTimeDO.setNoworkTime2(item.getValue2().size() == 1 ? null : sdf.format(Date.parse(item.getValue2().get(1).toString())));

            valueThing = item.getValuething();
            valuethingName = ObjectUtil.isEmpty(valueThing) ? "" :
                    (valueThing.equals("选项1") ? "排料时间" :
                            (valueThing.equals("选项2") ? "清扫时间" :
                                    (valueThing.equals("选项3") ? "维修时间" :
                                            (valueThing.equals("选项4") ? "开会时间" :
                                                    (valueThing.equals("选项5") ? "培训时间" :
                                                            (valueThing.equals("选项6") ? "设备保养时间" :
                                                                    (valueThing.equals("选项7") ? "其它" :"")))))));
            workTimeDO.setNoworkThing(valuethingName);
            workTimeDO.setPersonCount(item.getPersoncount() == null ? null : item.getPersoncount());
            workTimeDO.setTotalTime(item.getTotaltime() == null ? null : item.getTotaltime().toString());
//            if (ObjectUtil.isNotEmpty(item.getTotaltime())) totalAllTime = totalAllTime + new Long(item.getTotaltime());
            listTime.add(workTimeDO);
        }
        //合计作业时间
        String totalWorkTime = result.get("totalWorkTime")==null?null:result.get("totalWorkTime").toString();
        if(!ObjectUtils.isEmpty(totalWorkTime)){
            mapResult.put("totalWorkTime", totalWorkTime.substring(0,totalWorkTime.lastIndexOf("钟")+1));
        }else{
            mapResult.put("totalWorkTime", "00天00小时00分钟");
        }
        //合计无勤时间
        String totalNoWorkTime = result.get("totalNoWorkTime")==null?null:result.get("totalNoWorkTime").toString();
        if(!ObjectUtils.isEmpty(totalNoWorkTime)){
            mapResult.put("totalNoWorkTime", totalNoWorkTime.substring(0,totalNoWorkTime.lastIndexOf("钟")+1));
        }else{
            mapResult.put("totalNoWorkTime","00天00小时00分钟");
        }
        //合计人数
        mapResult.put("totalPersonCount", result.get("totalPersonCount"));
        //合计时间
//        String totalAllTimeTemp = result.get("totalAllTime")==null?null:result.get("totalAllTime").toString();
//        mapResult.put("totalAllTime", totalAllTimeTemp.substring(0,totalAllTimeTemp.lastIndexOf("钟")+1));
        mapResult.put("totalAllTime", result.get("totalAllTime"));
        //组别
        if (ObjectUtil.isNotEmpty(result.get("mGroup"))){
            String mGroup = result.get("mGroup").toString();
            String mGroupStr = mGroup.equals("0") ? "A" :
                                ( mGroup.equals("1") ? "B" : "C" );
            result.getOrDefault("mGroup",mGroupStr);
            mapResult.put("mGroup", mGroupStr);
        }
//        result.getOrDefault("mGroup",0)

        //决裁
        mapResult.put("approverName", result.get("approverName"));

        //辅助决裁
        mapResult.put("auditorName", result.get("auditorName"));

        //担当者
        mapResult.put("staffingName", result.get("staffingName"));
        //应出勤人员
        mapResult.put("shouldBeAttendance", result.get("shouldBeAttendance"));
        //实际出勤人员
        mapResult.put("realAttendance", result.get("realAttendance"));
        //出勤偏差
        mapResult.put("attendanceBias", result.get("attendanceBias"));
        //备注
        mapResult.put("note", result.get("note"));

        //指标书编号
        mapResult.put("mpiNo", result.get("mpiNo"));

        //客户名
        mapResult.put("clientName", result.get("clientName"));

        //设备名
        mapResult.put("deviceNo", result.get("deviceNo"));

        //品名
        mapResult.put("materielName", result.get("materielName"));

        //规格/型号
        mapResult.put("specification",result.get("specification"));

        //产品容量
        mapResult.put("productCapacity", result.get("productCapacity"));

        //重量
        mapResult.put("weight", result.get("weight"));

        //指标数量
        mapResult.put("instructionQty", result.get("instructionQty"));

        //开始LOT NO
        mapResult.put("lotNoStart", result.get("lotNoStart"));

        //结束LOT NO
        mapResult.put("lotNoEnd", result.get("lotNoEnd"));

        //良品数量
        mapResult.put("productionQty", result.get("productionQty"));

        //不良数量
        mapResult.put("inspectionQty", result.get("inspectionQty"));

        //模具型号
        mapResult.put("moldModel", result.get("moldModel"));

        //粉碎发生量
        mapResult.put("amountOfCrushing", result.get("amountOfCrushing"));
        //可粉碎块料
        mapResult.put("totalCanCrushed", result.get("totalCanCrushed"));
        //不可粉碎块料
        mapResult.put("totalNotCrushed", result.get("totalNotCrushed"));
        //不良数量2
        mapResult.put("inspectionQty2", result.get("inspectionQty2"));
        //不良数量3
        mapResult.put("inspectionQty3", result.get("inspectionQty3"));
        //边角料
        mapResult.put("leftoverMaterial", result.get("leftoverMaterial"));
        //当班已报工数量
        mapResult.put("totalReportedWork", result.get("totalReportedWork"));
        //报工人员
        mapResult.put("reportWorkers", result.get("reportWorkers"));
        //使用盖注入口#1数量
        mapResult.put("useCoverOneQuantity", result.get("useCoverOneQuantity"));
        //使用盖注入口#1
        mapResult.put("useCoverOneStatus", (boolean)result.get("useCoverOneStatus") ? "合格" : "不合格");
        //使用盖注入口#1作业者
        mapResult.put("useCoverOneUser", result.get("useCoverOneUser"));
        //使用盖注入口#2 数量
        mapResult.put("useCoverTwoQuantity", result.get("useCoverTwoQuantity"));
        //使用盖注入口#2
        mapResult.put("useCoverTwoStatus", (boolean)result.get("useCoverTwoStatus") ? "合格" : "不合格");
        //使用盖注入口#2作业者
        mapResult.put("useCoverTwoUser", result.get("useCoverTwoUser"));


        //使用盖注入口#1保护盖
        mapResult.put("protectiveCoverOne", result.get("protectiveCoverOne"));
        //使用盖注入口#1保护盖数量
        mapResult.put("quantityOne", result.get("quantityOne"));
        //使用盖注入口#2保护盖
        mapResult.put("protectiveCoverTwo", result.get("protectiveCoverTwo"));
        //使用盖注入口#2保护盖数量
        mapResult.put("quantityTwo", result.get("quantityTwo"));

        //
        //原料投入量
        String feedingMaterialJson = JSONObject.toJSONString(result.get("feedingMaterial"));
        JSONArray feedingMaterial = new JSONArray();
        Object b = JSON.parse(feedingMaterialJson);
        if (!ObjectUtils.isEmpty(b)) {
            Object c = JSON.parse(b.toString());
            feedingMaterial = JSON.parseArray(c.toString());
        }
        //原料投入量
        String feedingMaterialJson2 = JSONObject.toJSONString(result.get("feedingMaterial2"));
        JSONArray feedingMaterial2 = new JSONArray();
        Object b22 = JSON.parse(feedingMaterialJson2);
        if (!ObjectUtils.isEmpty(b22)) {
            Object c2 = JSON.parse(b22.toString());
            feedingMaterial2 = JSON.parseArray(c2.toString());
        }
//原料理论投入量1
        for (int i = 0; i < feedingMaterial.size(); i++) {
            JSONObject rowJSON = feedingMaterial.getJSONObject(i);
            if (i == 0) {
                mapResult.put("yuanliao1", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue1", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 1) {
                mapResult.put("yuanliao2", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue2", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 2) {
                mapResult.put("yuanliao3", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue3", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 3) {
                mapResult.put("yuanliao4", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue4", rowJSON == null ? null : rowJSON.getString("count"));
            }
        }

        //原料理论投入量2
        for (int i = 0; i < feedingMaterial2.size(); i++) {
            JSONObject rowJSON = feedingMaterial2.getJSONObject(i);
            if (i == 0) {
                mapResult.put("yuanliao21", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue21", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 1) {
                mapResult.put("yuanliao22", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue22", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 2) {
                mapResult.put("yuanliao23", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue23", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 3) {
                mapResult.put("yuanliao24", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuanliaovalue24", rowJSON == null ? null : rowJSON.getString("count"));
            }
        }

        String feedingMaterialRealityJson = JSONObject.toJSONString(result.get("feedingMaterialReality"));
        JSONArray feedingMaterialReality = new JSONArray();
        Object b2 = JSON.parse(feedingMaterialRealityJson);
        if (!ObjectUtils.isEmpty(b)) {
            Object c2 = JSON.parse(b2.toString());
            feedingMaterialReality = ObjectUtils.isEmpty(c2) ? null : JSON.parseArray(c2.toString());
        }
        result.put("feedingMaterialReality", feedingMaterialReality);
        //原料实际投入量
        for (int i = 0; i < feedingMaterialReality.size(); i++) {
            JSONObject rowJSON = feedingMaterialReality.getJSONObject(i);
            if (i == 0) {
                mapResult.put("yuansjliao1", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuansjliaovalue1", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 1) {
                mapResult.put("yuansjliao2", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuansjliaovalue2", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 2) {
                mapResult.put("yuansjliao3", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuansjliaovalue3", rowJSON == null ? null : rowJSON.getString("count"));
            }
            if (i == 3) {
                mapResult.put("yuansjliao4", rowJSON == null ? null : rowJSON.getString("name"));
                mapResult.put("yuansjliaovalue4", rowJSON == null ? null : rowJSON.getString("count"));
            }
        }
//        Object c = JSON.parse(b.toString());
//        JSONArray feedingMaterial = JSON.parseArray(c.toString());
//        result.put("feedingMaterial", feedingMaterial);
        if (result.containsKey("rawMaterialRatio") && !ObjectUtils.isEmpty(result.get("rawMaterialRatio"))) {
            String str = (String) result.get("rawMaterialRatio");
            JSONObject ratio = JSON.parseObject(str);
            result.put("rawMaterialRatio", ratio);
            //原料配比
            mapResult.put("rawmaterialnameOne", ratio.getString("name1"));
            mapResult.put("rawmaterialnameTwo", ratio.getString("name2"));
            mapResult.put("rawmaterialnameThree", ratio.getString("name3"));
            mapResult.put("rawmaterialnameFive", ratio.getString("name5"));
            mapResult.put("rawmaterialnameSix", ratio.getString("name6"));
            mapResult.put("rawmaterialnameSeven", ratio.getString("name7"));
            mapResult.put("rawmaterialnameNine", ratio.getString("name9"));
            mapResult.put("rawmaterialnameTen", ratio.getString("name10"));
            mapResult.put("rawmaterialnameEleven", ratio.getString("name11"));
            mapResult.put("proportionOne", ratio.getString("proportion1"));
            mapResult.put("proportionTwo", ratio.getString("proportion2"));
            mapResult.put("proportionThree", ratio.getString("proportion3"));
            mapResult.put("proportionFive", ratio.getString("proportion5"));
            mapResult.put("proportionSix", ratio.getString("proportion6"));
            mapResult.put("proportionSeven", ratio.getString("proportion7"));
            mapResult.put("proportionNine", ratio.getString("proportion9"));
            mapResult.put("proportionTen", ratio.getString("proportion10"));
            mapResult.put("proportionEleven", ratio.getString("proportion11"));
        }
        //树脂块状料
        mapResult.put("badWasteMaterielName", result.get("badWasteMaterielName"));
        //粉碎发生量(KG)
        mapResult.put("amountOfCrushingMaterielName", result.get("amountOfCrushingMaterielName"));
        //粒子形态
        mapResult.put("granuleForm", result.get("granuleForm"));
        mapResult.put("granuleForm2", result.get("granuleForm2"));
        //树脂形态
        mapResult.put("resinForm", result.get("resinForm"));
        mapResult.put("resinForm2", result.get("resinForm2"));
        //桶形态
        mapResult.put("bucketForm", result.get("bucketForm"));
        mapResult.put("bucketForm2", result.get("bucketForm2"));
        //卡箍数量
        mapResult.put("latheDogNormQty", result.get("latheDogNormQty"));
        mapResult.put("latheDogActualQty", result.get("latheDogActualQty"));
        //使用盖
        mapResult.put("useCoverOne", result.get("useCoverOne"));
        mapResult.put("useCoverTwo", result.get("useCoverTwo"));
//        //成型生产指示
//        Map<String, Object> mpi = moldingProductionInstructionService
//            .getDetailInfo((Long) result.get("mpiId"));
//        result.put("mpi", mpi);
        //成型生产指示
        Map<String, Object> mpi = moldingProductionInstructionService
                .getDetailInfoTwo((Long) result.get("mpiId"));
        result.put("mpi", mpi);

        //不良现况
        String badSituationJson = String.valueOf(result.get("badSituation"));
        JSONArray badSituation = JSON.parseArray(badSituationJson);
        result.put("badSituation", badSituation);
        List<BadSituationDO> listBadSituation=new ArrayList<>();
        if(badSituation!=null) {
            listBadSituation = JSONArray.parseArray(badSituation.toJSONString(), BadSituationDO.class);
        }
        //未达要因
//        String failedReachJson = String.valueOf(result.get("failedReach"));
//        JSONArray failedReach = JSON.parseArray(failedReachJson);
//        result.put("failedReach", failedReach);
//        List<FailedReachDO> listFailedReach=new ArrayList<>();
//        if(badSituation!=null) {
//            listFailedReach = JSONArray.parseArray(failedReach.toJSONString(), FailedReachDO.class);
//        }

        JSONArray failedReach = new JSONArray();
        Object failedReach1 = result.get("failedReach");
        List<FailedReachDO> listFailedReach=new ArrayList<>();
        if(ObjectUtil.isNotEmpty(failedReach1)) {
            failedReach = JSON.parseArray(failedReach1.toString());
            listFailedReach = JSONArray.parseArray(failedReach.toJSONString(), FailedReachDO.class);
        }
        result.put("failedReach", failedReach);
        //成型设备重要参数
        String importantParametersMoldingEquipmentJson = String
                .valueOf(result.get("importantParametersMoldingEquipment"));
        Map<String, Object> importantParametersMoldingEquipment = JSON
                .parseObject(importantParametersMoldingEquipmentJson);
        result.put("importantParametersMoldingEquipment", importantParametersMoldingEquipment);
        //冷却机温度
        mapResult.put("temperature", importantParametersMoldingEquipment.get("temperature"));
        //空气压力
        mapResult.put("air", importantParametersMoldingEquipment.get("air"));
        //成型时间
        mapResult.put("time", importantParametersMoldingEquipment.get("time"));
        //一次冷却时间
        mapResult.put("disposable", importantParametersMoldingEquipment.get("disposable"));
        //设备异常现况
        String equipmentAbnormalStatusJson = String.valueOf(result.get("equipmentAbnormalStatus"));
        JSONArray equipmentAbnormalStatus = JSON.parseArray(equipmentAbnormalStatusJson);
        result.put("equipmentAbnormalStatus", equipmentAbnormalStatus);
        List<EquipmentAbnormalStatusNewDO> listEquipmentNew=new ArrayList<>();
        Long totalEquipmentAbnormalTime = 0l;
        if(equipmentAbnormalStatus!=null) {
            List<EquipmentAbnormalStatusDO> listEquipment = JSONArray.parseArray(equipmentAbnormalStatus.toJSONString(), EquipmentAbnormalStatusDO.class);
            listEquipmentNew = new ArrayList<>();
            for (EquipmentAbnormalStatusDO equipmentAbnormalStatusDO : listEquipment) {
                EquipmentAbnormalStatusNewDO item = new EquipmentAbnormalStatusNewDO();
                item.setAname(equipmentAbnormalStatusDO.getAname());
                item.setQuestion(equipmentAbnormalStatusDO.getQuestion());
                item.setMethod(equipmentAbnormalStatusDO.getMethod());
                item.setName(equipmentAbnormalStatusDO.getName());
                item.setId(equipmentAbnormalStatusDO.getId());
                item.setRemark(equipmentAbnormalStatusDO.getRemark());
                if (ObjectUtil.isNotEmpty(equipmentAbnormalStatusDO.getTime())) {
                    item.setEquipmentAbnormalStartTime(DateUtil.format(equipmentAbnormalStatusDO.getTime().get(0),"yyyy-MM-dd HH:mm:ss" ));
                    item.setEquipmentAbnormalEndTime(DateUtil.format(equipmentAbnormalStatusDO.getTime().get(1),"yyyy-MM-dd HH:mm:ss" ));
                    listEquipmentNew.add(item);
                    totalEquipmentAbnormalTime = totalEquipmentAbnormalTime + DateUtil.between(equipmentAbnormalStatusDO.getTime().get(0),equipmentAbnormalStatusDO.getTime().get(1), DateUnit.MINUTE);
                }
            }
        }
        //设备异常现况总时间
        mapResult.put("totalEquipmentAbnormalTime",totalEquipmentAbnormalTime + "");
        //特记与传达事项
        mapResult.put("specialNoteItem",result.get("specialNoteItem"));
        String excelName = "成型日报";
        String templateFileName = localPath + File.separator + basePath + File.separator + "templates" + File.separator + "cxrb.xlsx";
        try

        {
            ExcelUtil.exportExcel(response, listTime, listBadSituation, listFailedReach, listEquipmentNew, mapResult, excelName, templateFileName, "成型日报");
        } catch(
                Exception e)

        {
            e.printStackTrace();
        }
    }
}
